<?
layout("/inc/layout.html",{title:sysTitle}){
?>

<div id="page-wrapper">
	<!--BEGIN TITLE & BREADCRUMB PAGE-->
	<div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
		<div class="page-header pull-left">
			<div class="page-title">权重配置</div>
		</div>
		<ol class="breadcrumb page-breadcrumb pull-left">
			<li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i
				class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li>统一检索管理&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li class="active">权重配置</li>
		</ol>

		<div class="clearfix"></div>
	</div>
	<!--END TITLE & BREADCRUMB PAGE-->
	<!--BEGIN CONTENT-->
	<div class="page-content">
		<!--BEGIN CONTENT-->
		<div class="row">
			<ul id="generalTab" class="nav nav-tabs ul-edit responsive">
				<li class="active"><a href="#dp-tab" data-toggle="tab">字段权重</a>
				</li>
				<li><a href="#op-tab" data-toggle="tab"
					onclick="queryrelevance()">自定义权重</a></li>
			</ul>
			<div id="generalTabContent" class="tab-content responsive">
				<div id="dp-tab" class="tab-pane fade in active">
					<div class="row mbl">
						<div class="col-lg-12">
							<div class="input-group-sm mbs">
								<table style="width: 95%;">
								<tr height="50">
									<td align="right">中文名称&nbsp;&nbsp;</td>
									<td>
										<input type="text" class="form-control" style="width: 100%;" id="nameZh" name="nameZh" />
									</td>
									<td align="right">英文名称&nbsp;&nbsp;</td>
									<td>
										<input type="text" class="form-control" style="width: 100%;" id="nameEn" name="nameEn" />
									</td>
									<td align="right">所属类&nbsp;&nbsp;</td>
									<td>
										<select id="parentClassid" class="form-control" style="width: 100%;">
											<option selected='selected' value="">请选择</option>
											<?for(c in classes){?>
												<option value="${c.id}">${c.nameZh}</option>
											<?}?>
										</select>
									</td>
								</tr>
								<tr height="50">
<!-- 									<td align="right">是否公共字段&nbsp;&nbsp;</td> -->
<!-- 									<td> -->
<!-- 										<select id="commonality" class="form-control" style="width: 100%;"> -->
<!-- 											<option selected='selected' value="">请选择</option> -->
<!-- 											<option value="0">是</option> -->
<!-- 											<option value="1">否</option> -->
<!-- 										</select> -->
<!-- 									</td> -->
									<td align="right">范围&nbsp;&nbsp;</td>
									<td>
										<select id="scope" class="form-control" style="width: 100%;">
											<option selected='selected' value="">请选择</option>
											<option value="0">全库有效</option>
											<option value="1">单库有效</option>
										</select>
									</td>
								</tr>
								<tr height="50">
									<td></td>
									<td>
										<button class="btn btn-sm btn-success" style="margin-right: 10px;" onclick="fieldList()">搜索</button>
										<button class="btn btn-sm btn-success" style="margin-right: 10px;" onclick="fieldqk()">清空</button>
										<button class="btn btn-sm btn-red" onclick="fieldAddUpalod(0,0,0)">新建字段权重</button>
									</td>
								</tr>
							</table>
							</div>
						</div>
					</div>

					<table class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
						<thead>
							<tr>
								<th>序号</th>
								<th>中文名称</th>
								<th>英文名称</th>
								<th>所属类</th>
<!-- 								<th>是否公共字段</th> -->
								<th>范围</th>
								<th>字段权重</th>
								<th>可操作</th>
							</tr>

						</thead>
						<thead id="fieldTable">
						</thead>
					</table>
					<div id="page1" style="text-align: center; margin-top: 20px;"></div>
				</div>
				<div id="op-tab" class="tab-pane fade">
					<div class="row mbl">
						<div class="col-lg-12">
							<div class="input-group-sm mbs">
								<table style="width: 95%;">
								<tr height="50">
									<td align="right">中文名称&nbsp;&nbsp;</td>
									<td>
										<input type="text" class="form-control" style="width: 100%;" id="customsnameZh" name="customsnameZh" />
									</td>
									<td align="right">英文名称&nbsp;&nbsp;</td>
									<td>
										<input type="text" class="form-control" style="width: 100%;" id="customsnameEn" name="customsnameEn" />
									</td>
									<td align="right">字段值&nbsp;&nbsp;</td>
									<td>
										<input type="text" class="form-control" style="width: 100%;" id="customsfieldValue" name="customsfieldValue" />
									</td>
									</tr>
									<tr height="50">
									<td align="right">所属类&nbsp;&nbsp;</td>
									<td>
										<select id="customsparentClassid" class="form-control" style="width: 100%;">
											<option selected='selected' value="">请选择</option>
											<?for(c in classes){?>
												<option value="${c.id}">${c.nameZh}</option>
											<?}?>
										</select>
									</td>
<!-- 									<td align="right">是否公共字段&nbsp;&nbsp;</td> -->
<!-- 									<td> -->
<!-- 										<select id="customscommonality" class="form-control" style="width: 100%;"> -->
<!-- 											<option selected='selected' value="">请选择</option> -->
<!-- 											<option value="0">是</option> -->
<!-- 											<option value="1">否</option> -->
<!-- 										</select> -->
<!-- 									</td> -->
									<td align="right">范围&nbsp;&nbsp;</td>
									<td>
										<select id="customsscope" class="form-control" style="width: 100%;">
											<option selected='selected' value="">请选择</option>
											<option value="0">全库有效</option>
											<option value="1">单库有效</option>
										</select>
									</td>
								</tr>
								<tr height="50">
									<td></td>
									<td>
										<button class="btn btn-sm btn-success" style="margin-right: 10px;" onclick="querycustomsList()">搜索</button>
										<button class="btn btn-sm btn-success" style="margin-right: 10px;" onclick="customsqk()">清空</button>
										<button class="btn btn-sm btn-red" style="margin-left: 10px;" onclick="customsAddUpload(0,0)">新建自定义权重</button>
									</td>
								</tr>
							</table>
							</div>
						</div>
					</div>

					<table
						class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
						<thead>
							<tr>
								<th>序号</th>
								<th>中文名称</th>
								<th>英文名称</th>
								<th>字段值</th>
								<th>所属类</th>
<!-- 								<th>是否公共字段</th> -->
								<th>范围</th>
								<th>字段权重</th>
								<th>可操作</th>
							</tr>
						</thead>
						<thead id="kfindMemeber">
						
						</thead>
					</table>
					<div id="page2" style="text-align: center; margin-top: 20px;"></div>
				</div>
				<!--END TITLE & BREADCRUMB PAGE-->
				<!--BEGIN CONTENT-->


			</div>


			<!--END CONTENT-->
		</div>


		<!--END CONTENT-->
	</div>
</div>

<?} ?>
<script>
	var fieldid;
	var cname;
	var fieldcurr;
	var customcurr;
	var fieldaddupds=0;
	var customaddupds=0;
	$(function() {
		fieldList(fieldcurr);
		querycustomsList(customcurr);
	});

									/* 字段 start  */
	function getfieldId() {
		return fieldid;
	}
	function getcname() {
		return cname;
	}
	function getfieldaddupds() {
		return fieldaddupds;
	}
	function getfieldcurr() {
		return fieldcurr;
	}
	//字段新增和修改
	function fieldAddUpalod(fieldId,classeszh) {
		fieldid = fieldId;
		cname=classeszh;
		fieldaddupds=0;
		layer.open({
			type : 2,
			area : [ '600px', '510px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			title : '字段权重',
			//maxmin : true,  
			move : false,
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : [ "search-weight-fieldsAddUpload.html", 'no' ],
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.save();
			},
		});
	}
	//字段列表显示
	function fieldList(count) {
		fieldcurr=count;
		$.ajax({
				type : "post",
				url : "queryfieldList.do",
				data : {
					"nameZh":$("#nameZh").val(),
					"nameEn":$("#nameEn").val(),
// 					"isCommonDataProperty":$("#commonality").val(),
					"parentClassid":$("#parentClassid").val(),
					"scope":$("#scope").val(),
					"page":count || 1
				},
				dataType : "json",
				success : function(data) {
					var str = "";
					var fieldmuch;
					var datas = data[0].text;
// 					for(var j = 0; j < data.length; j++){
						for ( var i = 0; i < datas.length; i++) {
							var isCommonDataProperty='';
							var range='';
// 							if (data[j].text[i].isCommonDataProperty == 0) {
// 								isCommonDataProperty='是';
// 							} else {
// 								isCommonDataProperty='否';
// 							} 
							if (datas[i].range == 0) {
								range='全库有效';
							} else {
								range='单库有效';
							} 
							str += "<tr><td>"
									+ (i + 1)
									+ "</td><td><label><a href='#' onclick=\"fielddetails('"+ datas[i].id+ "','"+ datas[i].classesEn + "')\">"
									+ datas[i].nameZh
									+ "</a></label></td><td><label>"
									+ datas[i].nameEn
									+ "</label></td><td><label>"
									+ datas[i].classesEn
// 									+ "</label></td><td><label>"
// 									+ isCommonDataProperty
									+ "</label></td><td><label>"
									+ range
									+ "</label></td><td><label>"
									+ datas[i].heightValue
									+ "</label></td><td>"
									+ "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"fieldAddUpalod('"+ datas[i].id+ "','"+ datas[i].classesEn + "')\">"
									+ "编辑"
									+ "</button>&nbsp;&nbsp;&nbsp;"
									+ "<button type=\"button\" class=\"btn btn-default btn-xs\" onclick=\"delfield('"+ datas[i].id + "')\">"
									+ "删除"
									+ "</button></td></tr>";
						}
						fieldmuch=data[0].fieldsCount;
// 					}
					$("#fieldTable").html(str);
					laypage({
						cont : document.getElementById('page1'), //容器。值支持id名、原生dom对象，jquery对象,
						pages : fieldmuch, //总页数
						skip : true, //是否开启跳页
						skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
						curr : fieldcurr || 1,
						last: fieldmuch,
						groups : 6,//连续显示分页数
						jump : function(obj, first) { //触发分页后的回调
							if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
								fieldList(obj.curr);
								fieldcurr = obj.curr;
							}
						}
					});
				},
				error : function(data) {
					alert("请求失败");
				}
			});
	};
	//字段删除
	function delfield(delfield) {
		layer.confirm('确认删除吗?', {
		  	btn: ['确定','取消'] //按钮
		}, function(){
		  	$.ajax({
				type : "post",
				url : "fieldDelete.do",
				data : {
					"id" : delfield
				},
				dataType : "json",
				success : function(data) {
					fieldList();
					if(data == 'success'){
					
						layer.msg('删除成功');
					}else{
						layer.msg('删除失败');
					}
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}, function(){
		  	
		});
	}
	//清空
	function fieldqk(){
		$("#nameZh").val("");
		$("#nameEn").val("");
// 		$("#commonality").val("");
		$("#parentClassid").val("");
		$("#scope").val("");
		fieldList(1);
	}
	
	function fielddetails(detailsId,detailsnameen){
		fieldaddupds=1;
		fieldid =detailsId;
		cname=detailsnameen;
		layer.open({
			type : 2,
			area : [ '600px', '510px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			title : '字段权重',
			//maxmin : true,  
			move : false,
			skin : 'layui-layer-rim', //加上边框
			btn : [ '关闭' ],
			content : [ "search-weight-fieldsAddUpload.html", 'no' ],
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.gaun();
			},
		});
	}
											/* 字段 	end  */
											/* 自定义  start  */
		var customsId;	
		var customsClassesZh;
			
		function getCustomsId() {
			return customsId;
		}
		function getcustomsClassesZh() {
			return customsClassesZh;
		}
		function getcustomaddupds() {
			return customaddupds;
		}
		function getcustomcurr() {
			return customcurr;
		}
		//自定义新增与修改							
		function customsAddUpload(customsAddUploadId,cczh) {
			customaddupds=0;
			customsId = customsAddUploadId;
			customsClassesZh = cczh;
			layer.open({
				type : 2,
				area : [ '600px', '550px' ],
				fix : false, //不固定
				scrollbar : false,
				shadeClose : true,
				title : '自定义权重',
				//maxmin : true,  
				move : false,
				skin : 'layui-layer-rim', //加上边框
				btn : [ '保存 ', '关闭' ],
				content : [ "search-weight-customsAddUpload.html", 'no' ],
				yes : function(index, layer) {
					var iframeWin = parent.window[layer.find('iframe')[0]['name']];
					iframeWin.save();
				},
			});
		}
	//自定义列表
	function querycustomsList(customscm) {
		customcurr=customscm;
		$.ajax({
			type : "post",
			url : "querycustomsList.do",
			data : {
					"nameZh":$("#customsnameZh").val(),
					"nameEn":$("#customsnameEn").val(),
					"fieldValue":$("#customsfieldValue").val(),
// 					"isCommonDataProperty":$("#customscommonality").val(),
					"parentClassid":$("#customsparentClassid").val(),
					"scope":$("#customsscope").val(),
					"page":customscm || 1
			},
			dataType : "json",
			success : function(data) {
				var str = "";
				var customsmuch;
				var datas = data[0].text;
// 				for(var j = 0; j < data.length; j++){
					for ( var i = 0; i < datas.length; i++) {
						var isCommonDataProperty='';
						var range='';
// 						if (data[j].text[i].isCommonDataProperty == 0) {
// 							isCommonDataProperty='是';
// 						} else {
// 							isCommonDataProperty='否';
// 						} 
						if (datas[i].range == 0) {
							range='全库有效';
						} else {
							range='单库有效';
						} 
						str += "<tr><td>"
								+ (i + 1)
								+ "</td><td><label><a href='#' onclick=\"customsdetails('"+ datas[i].id+ "','"+ datas[i].classesEn + "')\">"
								+ datas[i].nameZh
								+ "</a></label></td><td><label >"
								+ datas[i].nameEn
								+ "</label></td><td><label>"
								+ datas[i].fieldValue
								+ "</label></td><td><label>"
								+ datas[i].classesEn
// 								+ "</label></td><td><label>"
// 								+ isCommonDataProperty
								+ "</label></td><td><label>"
								+ range
								+ "</label></td><td><label>"
								+ datas[i].heightValue
								+ "</label></td><td>"
								+ "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"customsAddUpload('"+ datas[i].id+ "','"+ datas[i].classesEn + "')\">"
								+ "编辑"
								+ "</button>&nbsp;&nbsp;&nbsp;"
								+ "<button type=\"button\" class=\"btn btn-default btn-xs\" onclick=\"delcustoms('"+ datas[i].id + "')\">"
								+ "删除"
								+ "</button></td></tr>";
						}
						customsmuch=data[0].customsCount;
// 					}
					$("#kfindMemeber").html(str);
					laypage({
						cont : document.getElementById('page2'), //容器。值支持id名、原生dom对象，jquery对象,
						pages : customsmuch, //总页数
						skip : true, //是否开启跳页
						skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
						curr : customcurr || 1,
						last: customsmuch,
						groups : 6,//连续显示分页数
						jump : function(obj, first) { //触发分页后的回调
							if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
								querycustomsList(obj.curr);
								customcurr = obj.curr;
							}
						}
					});
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	//自定义删除
	function delcustoms(customsids) {
		layer.confirm('确认删除吗?', {
		  	btn: ['确定','取消'] //按钮
		}, function(){
		  	$.ajax({
				type : "post",
				url : "customsDelete.do",
				data : {
					"id" : customsids
				},
				dataType : "json",
				success : function(data) {
					querycustomsList();
					if(data == 'success'){
					
						layer.msg('删除成功');
					}else{
						layer.msg('删除失败');
					}
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}, function(){
		  	
		});
		}
	//清空
	function customsqk(){
		$("#customsnameZh").val("");
		$("#customsnameEn").val("");
// 		$("#customscommonality").val("");
		$("#customsparentClassid").val("");
		$("#customsscope").val("");
		$("#customsfieldValue").val("");
		querycustomsList(1);
	}
	//自定义详情							
	function customsdetails(customsdetailsid,customsdetailsnameen) {
		customsId = customsdetailsid;
		customsClassesZh = customsdetailsnameen;
		customaddupds=1;
		layer.open({
			type : 2,
			area : [ '600px', '550px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			title : '自定义权重',
			//maxmin : true,  
			move : false,
			skin : 'layui-layer-rim', //加上边框
			btn : [ '关闭' ],
			content : [ "search-weight-customsAddUpload.html", 'no' ],
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.guan();
			},
		});
	}
	
</script>